Thread: [WinAPI] Developing a color customizable program

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    [WinAPI] Developing a color customizable program

    I am trying to make my program fully color customizable. Thereīs a "Config Color" window where the user can click to open a ChooseColor common dialog to select TXT and BG color for all the controls. This color config is saved into a ini file.

    Until now, i was able to change the color of all the Static Controls, ListBoxes, Edit Controls and CheckBoxes via intercepting WM_CTLCOLORSTATIC, WM_CTLCOLORLISTBOX, WM_CTLCOLOREDIT and WM_CTLCOLORBTN.

    Looks good, but I got some problems thou: Thereīs really no point on changing BG and TXT color fo all the controls without changing my MainWindow BG and TABS BG.

    Well i have absolutely no idea on how to change the Main Window BG color yet, so any help will be fantastic.

    About changing the TABS BG color, someone told me that the only way would be to create an Owner Drawn Tab Control.
    I would like to know if thereīs really no other way cause iīve never done it Owner Drawn, it will be a pain in the ass to create it.


    If thereīs no other way, does anyone knows where to find a good example of how to implement and use Owner-Drawn Tabs using WinAPI? All I could find on my googling are VB and MFC examples. English is not my native language so maybe I skip something good. MSDN stuff on that was not clear enough for me.

    But please, tell me thereīs an easier way

    Just to make everything clear I am using my Tab Control like this right now:

    Code:
    static int tabnumber;
    TCITEM tci;
    NMHDR *nmptr;
    
    hwndTab = CreateWindowEx(0, WC_TABCONTROL, "", 
          WS_CHILD | TCS_RIGHTJUSTIFY | TCS_MULTILINE | /WS_VISIBLE,
          3, 0, 358, 383, mainWindow, (HMENU) 10, ((LPCREATESTRUCT) lParam)->hInstance,  NULL); 
    
          tci.mask=TCIF_TEXT; 
          tci.iImage=-1; 
          tci.pszText = "Status:"; 
          TabCtrl_InsertItem(hwndTab,0,&tci); 
          tci.pszText = "Servers/Logging Setup:"; 
          TabCtrl_InsertItem(hwndTab,1,&tci); 
          tci.pszText = "Looks:"; 
          TabCtrl_InsertItem(hwndTab,2,&tci); 
          tci.pszText = "Info:"; 
          TabCtrl_InsertItem(hwndTab,3,&tci);
    And I am intercepting TCN_SELCHANGE at WM_NOTIFY to catch the number of the active tab and calling functions at each os this cases to Show/Hide/Enable/Disable controls at each tab change:

    Code:
    case WM_NOTIFY:      
          nmptr=(LPNMHDR)lParam; 
          switch(nmptr->code) {
            case TCN_SELCHANGE:  
              updatetooltips();
              tabnumber = TabCtrl_GetCurSel((HWND)nmptr->hwndFrom); 
              switch(tabnumber) {
                case 0:
                showStatusTab();
                break;
                
                case 1:
                if (mwsize==0){
                  setsize();
                }
                showServersTab();
                break;
                
                case 2:
                if (mwsize==0){
                  setsize();
                }
                showLooksTab();
                break;          
              
                case 3:
                if (mwsize==0){
                  setsize();
                }
                showInfoTab();
                break;
              }
            default:
            return DefWindowProc (mainWindow, messages, wParam, lParam);
          }
    Once i add the 'TCS_OWNERDRAWFIXED' style to the Tab Control, the app compiles normally (with MingW, GCC 3.2) and the program works ok. The Tabs are displayed and work ok (I can change between them, so the TCN_SELCHANGE stuff is working). Only problem is that the Title in each TAB disappear and the TAB has some glitches. I really donīt know how to handle this Owner Drawn Tab...

    Thatīs it, hope someone can help me on that
    Thanks!

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    62

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Hey Rpet,

    Thanks for the link, lt has helped a lot!
    I have already adapted my code to it, now i can change the TAB CONTROL TXT and BG colors. Iīm now trying to find a way to change the BG color of the TABS theirselves.

    And if anyone else wants to help me, i still could not find a way to change the MainWindow BG color.

    Thanks

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Ok so the Tab dividers now are totally color customizable and that is great.

    But i canīt find a way to set a BG color for the tab 'pages' (sorry i donīt know how to name it, but iīm sure you all understand).

    Can anyone please at least confirm me that it is possible to do that? I would freak out if i found out that all the time searching and trying stuff was just a time loss...

    I canīt even remember one app that allows the user to set the BG color for the tab pages, thatīs why iīm worried.

    Thanks

  5. #5
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    that will take care of your main window bkcolor;

    u will use like this;

    routin;
    Code:
    CHOOSECOLOR cc;
    static HBRUSH hbrush;
    static COLORREF cr ;
    
    cr  = cc.rgbResult;
    
    hbrush = CreateSolidBrush(cr);
    
    SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hbrush);

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    I have seen some discussion here and at other forums about using WM_CTLCOLORBTN and i know i should not use it to change the colors of a PUSHBUTTON but what about a GroupBox?

    I am trying to set the color of the text of a button with a BS_GROUPBOX style with absolutely no success.

    Look, at WM_CREATE...
    Code:
          FirstGroup = CreateWindowEx (0, TEXT ("button"), TEXT("Status:"),
           WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
            9, 238, 346, 143, mainWindow, (HMENU) 1200, hInstance, NULL) ;
    At WM_COMMAND i deal with all my buttons, including one that selects a color for that GroupBox...
    Code:
    case IDC_BUTTONSTATUSGROUPTXTCOLOR:
    MessageBox (NULL, TEXT ("Step 1 ok!"), "DEBUGGING", MB_ICONERROR) ;
    if(ChooseColor(&choosecolor)) {
    currentcolorref = choosecolor.rgbResult;
    statusgrouptxtcolorref = currentcolorref;
    InvalidateRect(mainWindow, NULL, TRUE);	  
    return 0;   
    }
    And iīm taking care of WM_CTLCOLORBTN here:
    Code:
            case WM_CTLCOLORBTN:      
            if(colorhwnd==FirstGroup) {
            MessageBox (NULL, TEXT ("Step 2 ok!"), "DEBUGGING", MB_ICONERROR) ;
    
            SetTextColor((HDC)wParam, statusgrouptxtcolorref);
            SetBkMode((HDC)wParam, OPAQUE);
            SetBkColor((HDC)wParam, tabbgcolorref);
            logbrush.lbColor=tabbgcolorref;
            DeleteObject(hbrush);
            hbrush=CreateBrushIndirect(&logbrush);
            return (long)hbrush;
            return 0;
          }
    Up to now i can change the color of everything in my app except for the groupboxes text, you guys have any idea?

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Solved: To change the text color on a button with a BS_GROUPBOX style you have to intercept case WM_CTLCOLORSTATIC not WM_CTLCOLORBTN.

    Donīt ask me why, it sux but it works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM